跳到主要内容

画笔(Paint)

描述形状的绘制方式,包括填充或描边样式、厚度、 颜色、渐变和混合行为。

字段(Fields)

style

类型为 PaintStyle 的绘制样式。

self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
style = 'stroke',
})

join

拐角的描边连接行为。请参阅 StrokeJoin

self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
cap = 'round',
style = 'stroke',
})

cap

用于线条末端的描边端点样式。请参阅 StrokeCap

self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
join = 'round',
style = 'stroke',
})

thickness

描边路径的厚度。

self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
thickness = 4,
style = 'stroke',
})

blendMode

合成时使用的混合模式。请参阅 BlendMode

-- 创建一个具有颜色和相乘混合模式的新画笔
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
blendMode = 'multiply',
style = 'fill',
})

feather

羽化量。

self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
feather = 4,
style = 'stroke',
})

gradient

应用于填充的 渐变(Gradient)(如果存在)。

local g = Gradient.linear(Vector.xy(0, 0), Vector.xy(10, 0), {
{ position = 0, color = Color.rgb(255, 0, 0) },
{ position = 1, color = Color.rgb(0, 0, 255) },
})

self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
gradient = g,
style = 'fill',
})

color

颜色。请参阅 Color

self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
style = 'fill',
})

构造器(Constructors)

new

new() -> Paint

创建一个具有默认设置的新 画笔(Paint) 对象。

local paint = Paint.new()
paint.style = 'fill'
paint.color = Color.rgb(255, 200, 80)

with

with(values: PaintDefinition) -> Paint

根据提供的 PaintDefinition 初始化创建一个新的 Paint。

local strokePaint = Paint.with({
style = 'stroke',
thickness = 3,
color = Color.hex('#FF0066'),
join = 'round',
cap = 'round',
})

方法(Methods)

copy

copy(values: PaintDefinition?) -> Paint

返回一个复制此 Paint 的新 Paint,可选择使用提供的 PaintDefinition 中的值覆盖选定属性。 返回一个新的 Paint 实例。

local base = Paint.with({
style = 'fill',
color = Color.rgb(255, 0, 0),
})

local outline = base:copy({
style = 'stroke',
thickness = 4,
})